/*
Copyright 2011 Raymond Giorgi

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 */

package edu.pitt.cs3530.scripts;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.LinkedList;
import java.util.List;

/**
 * This class will accept connections from the application servers and do
 * nothing with them
 */
public class CatchAndHoldConnectionsScript {
	/**
	 * The main class will continually catch exceptions and hold them until the
	 * program is terminated externally
	 * 
	 * @param args
	 *            The first argument is the port to accept connections on
	 */
	public static void main(String args[]) {
		if (args.length != 1) {
			System.out.println("Usage: CatchAndHoldConnectionScript [port]");
			System.exit(0);
		}
		int port = Integer.parseInt(args[0]);
		List<Socket> sockets = new LinkedList<Socket>();
		try {
			ServerSocket ss = new ServerSocket(port);
			while (true) {
				Socket socket = ss.accept();
				sockets.add(socket);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
